package com.banmoon.mediator;

import java.util.List;
import java.util.Optional;

public class ConcreteMediator extends Mediator{

    @Override
    void getMessage(AbstractLandlord landlord, int type) {
        if(type==1)
            showHouseInfo(landlord);
        else
            System.out.println(landlord.getName() + "，你TM哪来的这么多要求");
    }

    @Override
    public House findHouse(int floor, int distance, boolean balcony, int rent) {
        for (AbstractLandlord landlord : getLandlordList()) {
            List<House> houseList = landlord.getHouseList();
            Optional<House> first = houseList.stream().filter(house -> house.getFloor() == floor
                    && house.getDistance() <= distance
                    && house.isBalcony() == balcony
                    && house.getRent() <= rent).findFirst();
            if(first.isPresent())
                return first.get();
        }
        return null;
    }

    private void showHouseInfo(AbstractLandlord landlord) {
        System.out.println("========== "+ landlord.getName() +"的房子 ==========");
        List<House> houses = landlord.getHouseList();
        houses.forEach(House::showInfo);
    }

}
